<?php
/**
 *@作者:MissZhang
 *@邮箱:<787727147@qq.com>
 *@创建时间:2022/10/10 16:12
 *@说明:进货商品订单
 */
namespace app\common\model;


use think\Model;

class StockOrder extends Model
{
    protected $pk = "order_id";
    // 定义时间戳字段名
    protected $createTime = 'add_time';
    //修改format类型
    protected $dateFormat = "Y-m-d H:i:s";
    protected $type=[
        'goods_price'   =>  'float',
        'total_amount'  =>  'float',
        'ship_price'    =>  'float',
        'order_amount'  =>  'float',
    ];
    public function getPkAttr($value,$data) {
        return $this->pk;
    }
    public function user(){
        return $this->hasOne(Users::class, 'user_id','user_id');
    }
    public function goods(){
        return $this->hasOne(StockGoods::class, 'goods_id','goods_id');
    }
    public function getConsigneeTextAttr($value,$data) {
        return $data['consignee'].":".$data['mobile'];
    }
    public function getOrderStatusTextAttr($value,$data) {
        $status = [-1=>'待支付',1=>'待发货',2=>'待收货',3=>'已完成'];
        return $status[$data['order_status']];
    }
    public function getPayTimeTextAttr($value,$data) {
        if ($data['pay_time']){
            return date($this->dateFormat,$data['pay_time']);
        }
        return '---';
    }
    public function getConfirmTimeTextAttr($value,$data) {
        if ($data['confirm_time']){
            return date($this->dateFormat,$data['confirm_time']);
        }
        return '---';
    }
    public function getShippingTimeTextAttr($value,$data) {
        if ($data['shipping_time']){
            return date($this->dateFormat,$data['shipping_time']);
        }
        return '---';
    }
    public function getAllAddressAttr($value,$data) {
        return $data['province'].$data['city'].$data['district'].$data['address'];
    }
    public function getTimeTextAttr($value,$data) {
        return date('Y-m-d',$data['add_time']);
    }
}
